package lambda;

/**
 * 方法引用
 */
public class LambdaDemo3 {
    public static void main(String[] args) {
        Shop shop = new Shop();
        //第一种创建线程的方式，继承Thread重写run方法
//        Thread t1 = new Thread(){
//            public void run(){
//                shop.buy();
//            }
//        };
//        Thread t2 = new Thread(){
//            public void run(){
//                shop.buy();
//            }
//        };

        //第二种创建线程的方式:实现Runnable接口
//        Thread t1 = new Thread(new Runnable() {
//            public void run() {
//                shop.buy();
//            }
//        });
//        Thread t2 = new Thread(new Runnable() {
//            public void run() {
//                shop.buy();
//            }
//        });

        //使用lambda表达式简化Runnable接口匿名内部类写法
//        Thread t1 = new Thread(()->shop.buy());
//        Thread t2 = new Thread(()->shop.buy());

        /*
            Thread t2 = new Thread(()->shop.buy());
                                   ^-----------^
                                        一样
            类似的:
            (a)->shop.buy(a)     也数以一样

            如果lambda表达式的参数列表与调用的方法参数列表一致，则可以写作下面的样子
            shop::buy
         */
        Thread t1 = new Thread(shop::buy);
        Thread t2 = new Thread(shop::buy);

    }
}

class Shop {
    public void buy() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + ":正在执行buy方法");
    }
}